package xyz.xgqn.media;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;

public class VideoView extends SurfaceView implements SurfaceHolder.Callback, View.OnClickListener {

    static {
        System.loadLibrary("media_jni");
    }

    public VideoView(Context context) {
        this(context, null);
    }

    public VideoView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public VideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        getHolder().addCallback(this);
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        setRender(holder.getSurface());
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }

    // 设置 surface
    private native void setRender(Surface surface);

    // 设置文件
    public native void setDataSource(String url);

    // 开始播放
    public native void start();

    // 恢复播放或者暂停
    private native void pauseOrResume();

    // 快进 0~1.0
    public native void seek(double position);

    // 获取当前的播放进度
    public native double getCurrentPosition();

    @Override
    public void onClick(View view) {

    }
}
